﻿using System;
using System.Collections.Generic;
using System.Web.Mvc;
using MvcApplication1.Models;
using System.Linq;

namespace MvcApplication1.Controllers
{
    public class Example1Controller : Controller
    {
        public ActionResult Index2()
        {
            return View(new Example1Arg(GridDatas));
        }        

        public ActionResult Grid(GridControllerArg arg)
        {
            IEnumerable<Example1Data> result;
            switch (arg.OrderBy.ToEnum<Example1OrderBy>())
            {
                case Example1OrderBy.C1:
                    result = GridDatas.OrderBy(_ => _.C1);
                    break;
                case Example1OrderBy.C2:
                    result = GridDatas.OrderBy(_ => _.C2);
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }
            return PartialView("Grid4", new Example1GridArg(arg.ContainerId, result));
        }

        private static IEnumerable<Example1Data> GridDatas
        {
            get
            {
                return new[]
                    {
                        new Example1Data("B21", "A22"),
                        new Example1Data("A11", "B12") 
                    };
            }
        }
    }
}